package com.huluobo.lc.kotlinim1803a.ui.activity

import android.os.Handler
import com.huluobo.lc.kotlinim1803a.R
import com.huluobo.lc.kotlinim1803a.contract.splash.SplashContract
import com.huluobo.lc.kotlinim1803a.contract.splash.SplashPresenter
import org.jetbrains.anko.startActivity

/**
 * @author Lc
 * @description: 功能需求,
 * 1.如果没有登录,延时2秒,跳转到登录界面
 * 2.如果已经登录,则跳转到主页面
 * @date :2020/9/10 19:00
 */
class SplashActivity : BaseActivity(), SplashContract.View {

    private val presenter =
        SplashPresenter(this)

    override fun init() {
        super.init()
        presenter.checkLoginStatus()
    }

    companion object {
        const val DELAY = 2000L
    }

    //委托给lazy,实现懒加载
    private val handler by lazy { //懒加载
        Handler()
    }

    override fun getLayoutResId(): Int =
        R.layout.activity_splash

    // * 1.如果没有登录,延时2秒,跳转到登录界面
    override fun onNotLoggedIn() {
        handler.postDelayed({
            startActivity<LoginActivity>()
            finish()
        },
            DELAY
        )
    }

    // * 2.如果已经登录,则跳转到主页面
    override fun onLoggedIn() {
        startActivity<MainActivity>()
        finish()
    }
}